﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;

namespace Milo.Framework
{
    public class TriggerControl : Control, ITriggerControl
    {
        public TriggerControl() { }
        public TriggerControl(IControl parent) : base(parent) { }
        public TriggerControl(string name, IControl parent) : base(name, parent) { }
        private ActionMethodInfo triggerAction;
        #region ITriggerControl Members

        public void AttachTriggerAction<TController>(Expression<Func<TController, System.Web.Mvc.ActionResult>> action) 
            where TController : class
        {
            triggerAction = new ActionMethodInfo(action);
        }

        public ActionMethodInfo GetActionMethodInfo()
        {
			if (triggerAction == null)
				throw new MiloException(string.Format("A trigger action has not been attached to {0}", Name));

            return triggerAction;
        }
        #endregion
    }
}
